package com.lc.test;

/**
 * @Author Lc
 * @Date 2023/7/26
 * @PackageName: com.lc.test
 * @ClassName: Sell
 * @Description:
 */

public class Sell {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        //三个线程
        new Thread(()->{
        for (int i = 0; i < 40; i++) {
            ticket.sale();
        } } ,"窗口1").start();
        new Thread(()->{
            for (int i = 0; i < 40; i++) {
                ticket.sale();
            } } ,"窗口2").start();
        new Thread(()->{
            for (int i = 0; i < 40; i++) {
                ticket.sale();
            } } ,"窗口3").start();
    }
}

class  Ticket {
    int number = 30;
    public synchronized void sale() {
        if(number > 0){
            System.out.println(Thread.currentThread().getName() + " : " + (number--) + " " + number);
        }

    }
}
